<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############



$tagname = preg_replace('/[^a-zA-Z0-9\_]/', '', get('block'));


if($DB->countRows($CONFIG->dbprefix.'cst_blocks', "tagname = '{$tagname}'")==0){
    JFX::addError('No block called "'.$tagname.'" is registered!');
    return;
}



$tData = $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}cst_blocks WHERE tagname = '{$tagname}'");




if(Antz_IntelliForm::submitted('edit-block')){
    $error = false;
    $newTagname = preg_replace('/[^a-zA-Z0-9\_]/', '', post('tagname'));

    if(trim($tagname)==''){
        $error = true;
        JFX::addFormError('tagname', 'Must not be empty!');
        JFX::addError('Tag Name cannot be empty!');
    }

    if($DB->countRows($CONFIG->dbprefix.'cst_blocks', "tagname = '{$newTagname}'")>0 && $newTagname != $tagname){
        $error = true;
        JFX::addFormError('tagname', 'Already registered');
        JFX::addError('Tag Name is already a tag');
    }

    if(!$error){
        $dbParams = array(
            'tagname' => $newTagname,
            'code' => $_POST['tagcontent']
        );
        $DB->update($CONFIG->dbprefix.'cst_blocks', $dbParams, "tagname = '{$tagname}'");
        JFX::addSuccess('Your blocks has been updated');
        die('<script type="text/javascript">
if(window.parent) window.parent.location = "'.$url.'";
</script>');
    }






}





$formFields = array(
    array(
        'name' => 'tagname',
        'value' => post('tagname', $tData['tagname']),
        'type' => 'text',
        'label' => 'Tag Name'
    ),
    array(
        'name' => 'tagcontent',
        'value' => array_key_exists('tagcontent', $_POST) ? $_POST['tagcontent'] : $tData['code'],
        'type' => 'code',
        'id' => 'tagcontent',
        'class' => 'php',
        'label' => 'Tag Code'
    ),
    array(
        'type' => 'submit',
        'value' => 'Update tag',
        'label' => '&nbsp;',
        'name' => 'submitBtn'
    )
);

echo JFX::makeRapidForm($formFields, 'New Tag Details', 'edit-block');





